﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls;
using TracNghiemTinHocDaiCuong.BIZ;
using TracNghiemTinHocDaiCuong.Common;
using TracNghiemTinHocDaiCuong.ThucThe;

namespace TracNghiemTinHocDaiCuong
{
    public partial class QuanLyBaiHoc : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LayDanhSach();
        }

        protected void gvBaiHoc_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvBaiHoc.PageIndex = e.NewPageIndex;
            gvBaiHoc.DataBind();
        }

        protected void btnTimKiem_Click(object sender, EventArgs e)
        {
            IList<BaiHoc> danhSach = BaiHocBIZ.TimKiem(txtTenBaiHoc.Text);
            if (danhSach.Count == 0)
                lblThongBao.Text = "Chưa có bản ghi để hiển thị";
            else
                lblThongBao.Text = "";
            gvBaiHoc.DataSource = danhSach;
            gvBaiHoc.DataBind();
        }

        protected void btnThemBaiHoc_Click(object sender, EventArgs e)
        {
            Response.Redirect("ThemBaiHoc.aspx");
        }

        protected void btnSuaBaiHoc_Click(object sender, EventArgs e)
        {
            Response.Redirect(string.Format("SuaBaiHoc.aspx?ID={0}", ViewState["idBaiHoc"]));
        }

        protected void btnXoaBaiHoc_Click(object sender, EventArgs e)
        {
            BaiHocBIZ.Xoa(Methods.ConvertNumber(ViewState["idBaiHoc"].ToString()));
            LayDanhSach();
        }

        protected void lkbtnBaiHoc_Click(object sender, CommandEventArgs e)
        {
            ViewState["idBaiHoc"] = Methods.ConvertNumber(e.CommandName);

            int i = Methods.ConvertNumber(e.CommandArgument.ToString());
            gvBaiHoc.Rows[i].Cells[0].CssClass = "row";
            gvBaiHoc.Rows[i].Cells[1].CssClass = "row";
            gvBaiHoc.Rows[i].Cells[2].CssClass = "row";
            
        }

        private void LayDanhSach()
        {
            gvBaiHoc.DataSource = BaiHocBIZ.LayDanhSach();
            gvBaiHoc.DataBind();
        }
    }
}